import instance from '@/utils/axios.js'

// 全部频道列表接口
function getChannelList () {
  return instance({
    url: '/v1_0/channels',
    method: 'get'
  })
}

export { getChannelList }

// 文章列表接口
function getArticleList ({ channel_id, timestamp }) {
  return instance({
    url: '/v1_0/articles',
    method: 'get',
    params: {
      with_top: 1,
      timestamp,
      channel_id
    }
  })
}

export { getArticleList }

// 获取新闻文章详情
function getArticleInfo(id) {
  return instance({
    url: `/v1_0/articles/${id}`
  })
}

export { getArticleInfo }

// 关注接口
function payFollowing(target) {
  return instance({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target,
    }
  })
}

export { payFollowing }

// 取消关注接口
function callFollowing(target) {
  return instance({
    url: `/v1_0/user/followings/${target}`,
    method: 'DELETE'
  })
}

export { callFollowing }

// 点赞接口
function payLiking(target) {
  return instance({
    url: '/v1_0/article/likings',
    method: 'post',
    data: {
      target
    }
  })
}

export { payLiking }

// 取消点赞接口
function callLiking(target) {
  return instance({
    url: `/v1_0/article/likings/${target}`,
    method: 'DELETE'
  })
}

export { callLiking }

// 喜欢文章接口
function payDislike(target) {
  return instance({
    url: '/v1_0/article/dislikes',
    method: 'post',
    data: {
      target
    }
  })
}

export { payDislike }

// 取消喜欢文章接口
function callDislike(target) {
  return instance({
    url: `/v1_0/article/dislikes/${target}`,
    method: 'DELETE'
  })
}

export { callDislike }

// 获取关键词列表
function getSuggestion(q) {
  return instance({
    url: '/v1_0/suggestion',
    method: 'get',
    params: {
      q
    }
  })
}

export { getSuggestion }

// 获取搜索结果
function getSearchList({ page, q}) {
  return instance({
    url: '/v1_0/search',
    method: 'get',
    params: {
      per_page: 10,
      page,
      q
    }
  })
}

export { getSearchList } 